layui.use(['form', 'layer', 'table', 'laydate', 'dropdown'], function () {
        const form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            table = layui.table,
            dropdown = layui.dropdown;

        //左侧菜单点击事件，其中 docDemoMenu1 对应的是菜单结构上的 id 指
        dropdown.on('click(docDemoMenu1)', function (options) {
            var othis = $(this); //当前菜单列表的 DOM 对象
            console.log(options); //菜单列表的 lay-options 中的参数
            switch (options.id) {
                case 1:
                    window.location.href = "archives01.html";
                    break;
                case 2:
                    window.location.href = "archives02.html";
                    break;
                case 3:
                    window.location.href = "archives03.html";
                    break;
            }
        });

        //列表
        const tableIns = table.render({
            elem: '#list',
            url: $.cookie("tempUrl") + 'hSysDoctorServicePack/selectListByDoctorId',
            where: {
                doctorId: $.cookie("doctorId")
            },
            method: "GET",
            request: {
                pageName: 'pageNum' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'msg' //状态信息的字段名称，默认：msg
                , countName: 'totalElements' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            },
            cellMinWidth: 95,
            page: true,
            height: "full-25",
            limits: [5, 10, 15, 20, 25],
            limit: 15,
            id: "dataTable",
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [[
                {field: 'id', title: '编号', minWidth: 90, align: 'center'},
                {field: 'name', title: '服务包名称', minWidth: 100, align: 'center'},
                {
                    title: '创建时间', minWidth: 180, align: "center", templet: function (d) {
                        return d.createTime;
                    }
                },
                {
                    title: '类型', minWidth: 90, align: 'center', templet: function (d) {
                        switch (d.types) {
                            case 1:
                                return "时间包";
                            case 2:
                                return "次数包";
                        }
                    }
                },
                {
                    field: 'money', title: '价格', minWidth: 90, align: 'center', templet: function (d) {
                        return d.money + '元';
                    }
                },
                {
                    field: 'num', title: '次数', minWidth: 90, align: 'center', templet: function (d) {
                        if (d.types === 1 || d.num === null) {
                            return '不限次'
                        } else {
                            return d.num + '次';
                        }
                    }
                },
                {
                    field: 'ageLimit', title: '服务时长', minWidth: 90, align: 'center', templet: function (d) {
                        return d.ageLimit + '个月';
                    }
                },
                {
                    field: 'sate', title: '状态', width: 100, align: 'center', templet: function (d) {
                        switch (d.sate) {
                            case 1:
                                return '<input type="checkbox" lay-filter="status" lay-skin="switch" value=' + d.id + ' lay-text="启用|禁用" checked disabled>';
                            case 2:
                                return '<input type="checkbox" lay-filter="status" lay-skin="switch" value=' + d.id + ' lay-text="启用|禁用" disabled>';
                        }
                    }
                },
                {title: '操作', width: 120, templet: '#userListBar', fixed: "right", align: "center"}
            ]],
            done: function (res, curr, count) {

            }
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            const checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add_btn':
                    const index = layui.layer.open({
                        title: "新增服务包",
                        type: 2,
                        area: ["500px", "570px"],
                        content: "fuwubaoAdd.html",
                        shadeClose: true,
                        success: function () {

                        }
                    });
                    break;
            }
        });

        //列表操作
        table.on('tool(test)', function (obj) {
            const layEvent = obj.event,
                data = obj.data;
            let index;
            switch (layEvent) {
                case 'look'://查看详情
                    index = layui.layer.open({
                        title: "处方单详情",
                        type: 2,
                        maxmin: true, //开启最大化最小化按钮
                        area: ["600px", "500px"],
                        content: "query01Info.html",
                        shadeClose: true,
                        success: function (layero, index) {
                            var body = layui.layer.getChildFrame('body', index);
                            body.find(".id").val(data.id);
                            form.render();
                            // setTimeout(function () {
                            //     layui.layer.tips('点击此处最大化', '.layui-layer-max', {
                            //         tips: 3
                            //     });
                            // }, 100)
                        }
                    });
                    break;
                case 'edit'://编辑
                    $.cookie('tempId', data.id, {path: '/'});
                    layui.layer.open({
                        title: "更新服务包",
                        type: 2,
                        area: ["500px", "570px"],
                        content: "fuwubaoUpd.html",
                        shadeClose: true,
                        success: function () {

                        }
                    });
                    break;
                case 'del'://删除
                    layer.confirm('确定删除此服务包？', {icon: 3, title: '提示信息'}, function (index) {
                        $.ajax({
                            url: $.cookie("tempUrl") + "hSysDoctorServicePack/deleteByPrimaryKey?id=" + data.id,
                            type: "DELETE",
                            success: function (result) {
                                layer.msg("删除成功");
                                // window.location.href = "informationList.html";
                            }
                        });
                        obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        // tableIns.reload();
                        layer.close(index);
                    });
                    break;
            }
        });
    }
);
